<template>
	<view :style="objColor">
		<customer></customer>
		<!-- <capsule v-if="!backType" title="订单详情" image="https://oos-cn.ctyunapi.cn/front-end/static/static/back.png" txtColor="#333333" :show_bol="false"></capsule>
		<homeNav v-if="backType==2" title="订单详情" image="https://oos-cn.ctyunapi.cn/front-end/static/static/back.png" txtColor="#333333" :show_bol="false" bgColor="#ffffff"></homeNav> -->
		<!-- orderSub/pages/orderSettlement/orderSettlement.wxml -->
		<image class="header-image" :src="(mixOtherIconList[5] && mixOtherIconList[5].icon)" style="width: 100%"></image>
		<view class="detCon">
			<view class="order">
				订单号：
				<view class="orderNo">{{ detailBill.busShowNo }}</view>
			</view>
			<view class="info">
				<!--  -->
				<view class="isDisplay">
					<view class="titCon">
						<image src="https://oos-cn.ctyunapi.cn/front-end/static/orderSub/images/pic.png" class="img">
						</image>
					</view>
					<view class="tit">
						<view class="titName">{{ detailBill.stationName }}</view>
						<view class="titInfoCon">
							<text class="tit1">
								{{ isv2g ? '放电时长：' : '充电时长：' }}
								<text class="txt2">{{ detailBill.difference ? detailBill.difference : '' }}min</text>
							</text>
							<text class="tit1">
								{{ isv2g ? '已放电量：' : '已充电量：' }}
								<text class="txt2">{{ detailBill.sumPower / 1000 }}kwh</text>
							</text>
						</view>
						<!-- #V2G功能 -->
						<view v-if="!isv2g">
							<text class="tit3">
								电费:￥{{ detailBill.powerBalance }} | 服务费:￥{{ detailBill.serviceBalance }}
							</text>
						</view>
					</view>
				</view>
			</view>

			<view class="detailBox">
				<!-- <view  class="img"></view> -->
				<view class="detail">
					<view class="txt1">{{ isv2g ? '收益明细' : '价格明细'}}</view>
					<view class="detailDisplay">
						<view class="txt2">支付方式</view>
						<!-- 微信支付分显示 -->
						<view class="txt3 flex-row-start" v-if="detailBill.wxppOrder">
							<image src="https://oos-cn.ctyunapi.cn/front-end/static/zhifufen_icon.png" class='zhifufen_icon'></image>
							微信支付分
						</view>
						<view class="txt3" v-else-if="detailBill.payMode == 6 && prepaidCardSwitch">储值卡</view>
						<view class="txt3" v-else>{{ detailBill.payAccountStr == '团队账户' ? '车队账户' :
                            detailBill.disposableOrder ? '充完即退' : detailBill.payAccountStr + '账户' }}</view>
					</view>
					<view class="detailDisplay" v-if="detailBill.disposableOrder">
						<view class="txt2">预充金额</view>
						<view class="acc">
							<view class="txt4">
								<text>￥</text>
								{{ detailBill.preFrozenAmount ? detailBill.preFrozenAmount.toFixed(2) : '-' }}
							</view>
						</view>
					</view>
					<view class="detailDisplay" v-else-if="detailBill.wxppOrder">
						<view class="txt2">预充金额</view>
						<view class="acc">
							<view class="txt4">
								<text>￥</text>
								{{ detailBill.preFrozenAmount ? detailBill.preFrozenAmount.toFixed(2) : '-' }}
							</view>
						</view>
					</view>
					<view class="detailDisplay" v-else>
						<view class="txt2">账户余额</view>
						<view class="acc">
							<view class="txt4" v-if="detailBill.payAccountStr == '个人'">
								<text>￥</text>
								{{ memberInfo.accountBalance ? memberInfo.accountBalance : '-' }}
								<text style="margin-left: 10rpx;">|</text>
							</view>
							<a @tap="rechargeVisible($event, { type: 'open' })" data-type="open"
								v-if="detailBill.payAccountStr == '个人' && !isTjhz()">去充值</a>
							<view class="txt4" v-if="detailBill.payAccountStr !== '个人'">
								<text v-if="memberInfo.deductMode !== 'TeamAccount'">￥</text>
								{{ memberInfo.deductMode == 'TeamAccount' ? '****' :
                                    memberInfo.carAccountBalance ? memberInfo.carAccountBalance : '-' }}
							</view>
						</view>
					</view>
					<view class="detailDisplay">
						<view class="txt2">{{ isv2g ? '放电收益' : '充电总费用' }}</view>
						<view class="txt4">
							<text>￥</text>
							{{ detailBill.busBalance ? detailBill.busBalance : '-' }}
						</view>
					</view>
					<view class="xian"></view>
					<view class="detailDisplay" style="margin-top: 70rpx" v-if="detailBill.memberDiscountBalance > 0">
						<view class="txt2">{{ detailBill.payAccountStr == '个人' ? '会员折扣(个人会员)' : '会员折扣(车队会员)' }}</view>
						<view class="txt5">
							<text>-￥</text>
							{{ detailBill.memberDiscountBalance ? detailBill.memberDiscountBalance : '--' }}
						</view>
					</view>
					<!-- <view class="detailDisplay" style="margin-top: 42rpx" v-if="detailBill.discountBalance > 0">
                        <view class="txt2">优惠活动({{ detailBill.ruleType == '1' ? '会员折扣' : detailBill.ruleType == '2' ? '累计优惠'
                            : '站点优惠' }})</view>
                        <view class="txt5">
                            <text>-￥</text>
                            {{ detailBill.discountBalance ? detailBill.discountBalance : '-' }}
                        </view>
                    </view> -->


					<!-- 831优惠展示 -->
					<!-- 原站点优惠改为电站促销, 新增集团折扣 -->
					<view class="detailDisplay" style="margin-top: 42rpx" v-if="detailBill.discountBalance > 0">
						<view class="txt2">电站促销</view>
						<view class="txt5">
							<text>-￥</text>
							{{ detailBill.discountBalance }}
						</view>
					</view>
					<view class="detailDisplay" style="margin-top: 42rpx" v-if="detailBill.groupDiscountBalance > 0">
						<view class="txt2">集团折扣</view>
						<view class="txt5">
							<text>-￥</text>
							{{ detailBill.groupDiscountBalance }}
						</view>
					</view>


					<view class="detailDisplay" style="margin-top: 42rpx" v-if="detailBill.deductibleBalance > 0">
						<view class="txt2">奖励金</view>
						<view class="txt5">
							<text>-￥</text>
							{{ detailBill.deductibleBalance ? detailBill.deductibleBalance : '-' }}
						</view>
					</view>
					<view class="detailDisplay" style="margin-top: 42rpx">
						<view class="txt2">优惠券</view>
						<view v-if="detailBill.payAccountStr == '个人'" class="txt5"
							@tap="parseEventDynamicCode($event, !detailBill.feeSingle ? 'goCoupon' : 'showFeeSingle')"
							:data-id="detailBill.id">
							<text>-￥</text>
							{{ detailBill.couponAmount }}
							<image v-if="detailBill.billStatus != 14" class="img"
								src="https://oos-cn.ctyunapi.cn/front-end/static/orderSub/images/turn.png"></image>
						</view>
						<view class="txt2" v-else>暂不可用</view>
					</view>

					<!-- 储值卡抵扣费用 -->
					<view class="detailDisplay" style="margin-top: 42rpx" v-if="detailBill.payMode== 6 && detailBill.payAccountStr == '个人' && prepaidCardSwitch">
						<view class="txt2">储值卡抵扣费用</view>
						<view class="txt5">
								<text>-￥</text>
								{{ detailBill.busBalance?detailBill.busBalance:'-' }}
						</view>
					</view>

					<view class="xian1"></view>
					<view class="detailDisplay" style="margin-top: 70rpx">
						<view></view>
						<view class="txt6">
							已优惠
							<text>￥</text>
							<view class="payNum1">{{ detailBill.allCouponAmount }}</view>
							，{{ isv2g ? '实收' : '应付'}}￥
							<view class="payNum2">{{ detailBill.actualBalance1 }}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="tips" v-if="detailBill.billStatus == 11">
				结算前可更改使用优惠券，
				<text>{{ getmsg }}秒</text>
				后将自动付款
			</view>
			<!-- <view
		  class="refundCon"
		  v-if="showPaidTips && (detailBill.billStatus == 12)"
		  @tap="showPaidTipsFun"
		>   
		  <image
		    src="https://oos-cn.ctyunapi.cn/front-end/static/orderSub/images/refundClose.png"
		  />
		  待支付{{detailBill.billPayLog[0].debt / 100}}元，已支付{{detailBill.billPayLog[0].paidAmount/100 }}
		</view>  -->
			<!-- 11待支付  12支付失敗 13 部分支付 14 已支付 -->

			<template v-if="!isv2g">
				<template v-if="detailBill.wxppOrder">
					<view v-if="detailBill.billStatus != 14">
						<view class="btn" @tap="payCharge" :data-id="detailBill.id" v-if="!detailBill.isPay">
							确定支付
							<text v-if="getmsg">（{{ getmsg ? getmsg + 's' : '' }}）</text>
						</view>
					</view>
					<view v-else class="btn1" @tap="" :data-id="detailBill.id">已支付</view>
				</template>

				<template v-else>
					<view class="btn" @tap="payCharge" :data-id="detailBill.id"
						v-if="detailBill.billStatus == 11 || detailBill.billStatus == 10 || detailBill.billStatus == 15">
						确定支付
						<text v-if="getmsg">（{{ getmsg ? getmsg + 's' : '' }}）</text>
					</view>
					<view class="btn1" @tap="" :data-id="detailBill.id"
						v-if="detailBill.billStatus == 13 || detailBill.billStatus == 12">
						请充值（待支付{{ detailBill.arrears }}元，已支付{{ detailBill.actualBalance }}）
					</view>
					<view class="btn1" @tap="" :data-id="detailBill.id" v-if="detailBill.billStatus == 14">已支付</view>
				</template>
			</template>

			<!-- 充值弹窗 -->
			<u-popup :show="showRecharge" mode='center' closeable
				custom-style="width:674rpx;height:482rpx;border-radius: 16rpx;" @close="rechargeVisible1">
				<Payment @getbalance="getMemberInfo" style="padding:32rpx"></Payment>
			</u-popup>
		</view>



		<!-- 异常被拦截的待支付订单和部分支付订单，用户移动端无法主动完成支付操作，用户点击【去支付】按钮时 弹窗提示：当前充电订单支付状态异常，请联系平台客服人员进行处理。订单号：XXXXXXXX-->
		<!-- 温馨提示 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="好的" confirmText="联系客服" title="温馨提示" @confirm="callAlert"
				@cancel="onCloseAlert">
				<view>
					<view class="alert_msg">
						{{ alertMsg }}
					</view>
				</view>
			</uni-popup-dialog>
		</uni-popup>

		<!-- 联系客服 -->
		<uni-popup ref="telephoneDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="取消" confirmText="呼叫" @confirm="callPhone" @cancel="onCloseCustomer">
				<view>
					<view class="infos">
						<view class="infoTitle">联系客服：</view><text class="infoValue">{{ serviceInfo.customerTelephone
                        }}</text>
					</view>
					<view class="infos">
						<view class="infoTitle">工作时间：</view>{{ serviceInfo.customerServiceTime }}
					</view>
				</view>
			</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	'use strict';
	import Payment from '@/components/payment/payment';
	import capsule from '../../../components/nav/nav';
	import homeNav from '../../../components/homeNav/homeNav';

	// exports.__esModule = true; // orderSub/pages/orderSettlement/orderSettlement.ts

	var app = getApp();

	var https_1 = require('./../../../api/https.js');

	// 831自动扣款增加接口
	import {
		delayDeductionChargeV2,
	} from '@/api/mobileUpdate';


	export default {
		components: {
			Payment,
			capsule,
			homeNav
		},
		data() {
			return {
				stationId: '',
				marketingSwitch: app.globalData.marketingSwitch,
				getmsg: 0,
				inter: '',
				showPaidTips: true,
				showRecharge: false,
				rechargeIndex: 0,
				customRechargePrice: '',
				priceTypeList: ['10', '30', '60', '100'],

				memberInfo: {
					deductMode: '',
					accountBalance: '',
					busBalance: '',
					memberDiscountBalance: '',
					discountBalance: '',
					deductibleBalance: '',
					couponAmount: '',
				},

				busId: '',

				detailBill: {
					busId: '',
					stationName: '',
					difference: '',
					sumPower: 0,
					powerBalance: '',
					serviceBalance: '',
					payAccountStr: '',
					ruleType: '',
					id: '',
					billStatus: 0,
					allCouponAmount: '',
					paidinAmount: ''
				},

				couponIdStr: null,
				money: '',
				couponType: '',
				deductibleBalanceCoupon: '',
				orderNo: '',
				debt: 0,
				paidAmount: 0,
				backType: 0,

				alertMsg: '',
				alertShow: false,
				serviceInfo: {
					customerTelephone: '',
					customerServiceTime: ''
				},
        isv2g: false, // #V2G功能
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			console.log("打印结算页面", options, options.busId)
			this.stationId = options.stationId
			if (options.busId) {
				this.busId = options.busId
			}
			if (options.backType) {
				this.backType = options.backType
			}
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			var pages = getCurrentPages();
			var currPage = pages[pages.length - 1];
			console.log(currPage)
			if (currPage.data) {
				this.setData({
					//将携带的参数赋值
					couponIdStr: currPage.data.couponIdStr,
					money: currPage.data.money,
					couponType: currPage.data.couponType,
					deductibleBalanceCoupon: currPage.data.deductibleBalanceCoupon
				});
			}

			this.getMemberInfo();
			this.getDelayPayBill1();
		},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {
			clearInterval(this.inter);
		},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {
			clearInterval(this.inter);
		},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		created: function() {
			this.getRefundAmount();
		},
		methods: {
			//获取客服电话及时间信息
			getRefundAmount: function() {
				var that = this;
				https_1.refundAmount().then(function(res) {
					if (res.code == 0) {
						that.setData({
							serviceInfo: res.data
						});
					}
				});
			},
			//联系客服 好的
			onCloseAlert: function() {
				this.$refs.alertDialog.close()
			},
			//联系客服弹窗打开
			callAlert: function() {
				this.$refs.alertDialog.close()
				this.$refs.telephoneDialog.open()
			},

			//联系客服 呼叫
			callPhone:async function() {
				this.$refs.telephoneDialog.close()
				//#ifdef APP-PLUS
					let result = await this.$store.dispatch("requestPermissions",'CALL_PHONE')
					if (result !== 1){
						return
					}else{
						uni.makePhoneCall({
							phoneNumber: this.serviceInfo.customerTelephone
						});
					}    
				//#endif
				//#ifdef MP-WEIXIN
					uni.makePhoneCall({
						phoneNumber: this.serviceInfo.customerTelephone
					});
				//#endif
			},
			//联系客服 取消
			onCloseCustomer: function() {
				this.$refs.telephoneDialog.close()
			},


			showPaidTipsFun: function() {
				this.showPaidTips = false;
			},
			//获取未结算订单
			getDelayPayBill1: function() {
				console.log('获取未结算订单方法,上个页面带过来的参数==>', this.couponIdStr, this.money, this.couponType, this
					.deductibleBalanceCoupon)

				var that = this;
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				https_1.getDelayPayBill({
					busId: that.busId
				}).then(function(res) {
					console.log('获取未结算订单接口===>>>>>>>>', res.data)

					var data = res.data;
					var money = that.money;
					console.log('billPayLog', data.billPayLog)
					// #V2G功能
					if (that.isV2GOption) {
						that.isv2g = data.disCharge ? true : false
					}

					if (data.actualBalance) {
						data.actualBalance = (data.actualBalance / 100).toFixed(2);
					} else {
						data.actualBalance = '0.00';
					}

					if (data.arrears) {
						data.arrears = (data.arrears / 100).toFixed(2);
					} else {
						data.arrears = '0.00';
					}


					if (data.busBalance) {
						data.busBalance = (data.busBalance / 100).toFixed(2);
					} else {
						data.busBalance = '0.00';
					}

					if (data.powerBalance) {
						data.powerBalance = (data.powerBalance / 100).toFixed(2);
					} else {
						data.powerBalance = '0.00';
					}

					if (data.serviceBalance) {
						data.serviceBalance = (data.serviceBalance / 100).toFixed(2);
					} else {
						data.serviceBalance = '0.00';
					}

					if (data.ruleType == '1') {
						data.discountBalance = '0.00';
					} else {
						data.discountBalance = (data.discountBalance / 100).toFixed(2);
					}

					// 集团折扣
					if (data.groupDiscountBalance) {
						data.groupDiscountBalance = (data.groupDiscountBalance / 100).toFixed(2);
					} else {
						data.groupDiscountBalance = '0.00';
					}

					if (data.contractBalance) {
						data.contractBalance = (data.contractBalance / 100).toFixed(2);
					} else {
						data.contractBalance = '0.00';
					}

					// 奖励金
					data.deductibleBalance = (data.deductibleBalance / 100).toFixed(2);

					if (data.powerCoupon) {
						data.powerCoupon = (data.powerCoupon / 100).toFixed(2);
					} else {
						data.powerCoupon = '0.00';
					}

					if (data.serviceCoupon) {
						data.serviceCoupon = (data.serviceCoupon / 100).toFixed(2);
					} else {
						data.serviceCoupon = '0.00';
					}

					if (data.cashCoupon) {
						data.cashCoupon = (data.cashCoupon / 100).toFixed(2);
					} else {
						data.cashCoupon = '0.00';
					}

					if (data.memberDiscountBalance) {
						data.memberDiscountBalance = (data.memberDiscountBalance / 100).toFixed(2);
					} else {
						data.memberDiscountBalance = '0.00';
					}
					if (res.data.timeS && res.data.timeE) {
						data.difference = that.getDateDiff(res.data.timeS, res.data.timeE);
					}

					if (that.couponType == 'FuWuFei') {
						if (data.serviceBalance - data.discountBalance - data.memberDiscountBalance > money) {
							money = money;
						} else {
							money = data.serviceBalance - data.discountBalance - data.memberDiscountBalance;
						} // console.log("打印FuWuFei",data.serviceBalance>money,money)
					}

					if (that.couponType == 'DianFei') {
						if ((+data.powerBalance) > (+money)) {
							money = money;
						} else {
							money = data.powerBalance;
						} // console.log("打印DianFei",data.powerBalance>money,money)
					}

					if (that.couponType == 'XianJin') {
						if (data.busBalance - data.discountBalance - data.memberDiscountBalance > money) {
							money = money;
						} else {
							money = data.busBalance - data.discountBalance - data.memberDiscountBalance;
						} // console.log("打印XianJin",data.busBalance>money,money)
					} // console.log("打印couponAmount11", (parseFloat(data.powerCoupon) + parseFloat(data.serviceCoupon) + parseFloat(data.cashCoupon)).toFixed(2),money)

					if (money) {
						data.couponAmount = parseFloat(money).toFixed(2);
					} else {
						data.couponAmount = (parseFloat(data.powerCoupon) + parseFloat(data.serviceCoupon) + parseFloat(data
							.cashCoupon)).toFixed(2);
					} // console.log("打印couponAmount",data.couponAmount,money)



					console.log("奖励金字段默认-data.deductibleBalance-->>>>", data.deductibleBalance)
					console.log("优惠券类型-that.couponType-->>>>", that.couponType)

					//fix:修复奖励金和优惠券同时抵扣情况的bug;;;
					if (!that.couponType) {
						// 1,处理默认优惠券选中的逻辑,拿接口反的三种券金额做处理
						// 默认优惠券金额-服务费金额, 处理是否显示奖励金
						let couponAmountReduceFwf = parseFloat(data.couponAmount) - parseFloat(data.serviceBalance)
						console.log("优惠券-服务费==???couponAmountReduceFwf...", couponAmountReduceFwf)
						if (data.serviceCoupon && parseFloat(data.serviceCoupon) > 0) {
							//服务费券
							if (parseFloat(data.deductibleBalance) > 0) {
								if (couponAmountReduceFwf >= 0) {
									// 大于0等于0,奖励金变成0,页面dom上自然不显示奖励金
									data.deductibleBalance = 0
								} else {
									// 不大于0,将奖励金显示为优惠券金额-服务费的剩余金额couponAmountReduceFwf
									data.deductibleBalance = data.deductibleBalance >= couponAmountReduceFwf ?
										couponAmountReduceFwf : data.deductibleBalance
								}
							}
						}
						if (data.powerCoupon && parseFloat(data.powerCoupon) > 0) {
							//电费券不用处理奖励金
							data.deductibleBalance = data.deductibleBalance
						}
						if (data.cashCoupon && parseFloat(data.cashCoupon) > 0) {
							//现金券
							if (parseFloat(data.deductibleBalance) > 0) {
								if (couponAmountReduceFwf >= 0) {
									// 大于0等于0,奖励金变成0,页面dom上自然不显示奖励金
									data.deductibleBalance = 0
								} else {
									// 不大于0,将奖励金显示为优惠券金额-服务费的剩余金额couponAmountReduceFwf
									data.deductibleBalance = data.deductibleBalance >= couponAmountReduceFwf ?
										couponAmountReduceFwf : data.deductibleBalance
								}
							}
						}
						console.log("奖励金字段处理完1111-->>>>", data.deductibleBalance)
					} else {
						// 2,处理选择优惠券后的逻辑 拿优惠券类型做判断
						// 选中后的优惠券金额-服务费金额, 处理是否显示奖励金
						let couponAmountReduceFwf2 = parseFloat(money) - parseFloat(data.serviceBalance)
						console.log("优惠券-服务费==???couponAmountReduceFwf2....", couponAmountReduceFwf2)
						if (that.couponType == 'FuWuFei') {
							//服务费券
							if (parseFloat(data.deductibleBalance) > 0) {
								if (couponAmountReduceFwf2 >= 0) {
									// 大于0等于0,奖励金变成0,页面dom上自然不显示奖励金
									data.deductibleBalance = 0
								} else {
									// 不大于0,将奖励金显示为优惠券金额-服务费的剩余金额couponAmountReduceFwf2
									data.deductibleBalance = data.deductibleBalance >= couponAmountReduceFwf2 ?
										couponAmountReduceFwf2 : data.deductibleBalance
								}
							}
						}
						if (that.couponType == 'DianFei') {
							//电费券不用处理奖励金
							data.deductibleBalance = data.deductibleBalance
						}
						if (that.couponType == 'XianJin') {
							//现金券
							if (parseFloat(data.deductibleBalance) > 0) {
								if (couponAmountReduceFwf2 >= 0) {
									// 大于0等于0,奖励金变成0,页面dom上自然不显示奖励金
									data.deductibleBalance = 0
								} else {
									// 不大于0,将奖励金显示为优惠券金额-服务费的剩余金额couponAmountReduceFwf2
									data.deductibleBalance = data.deductibleBalance >= couponAmountReduceFwf2 ?
										couponAmountReduceFwf2 : data.deductibleBalance
								}
							}
						}
						console.log("奖励金字段处理完2222-->>>>", data.deductibleBalance)

					}



					// 总优惠
					data.allCouponAmount = (
						parseFloat(data.couponAmount ? data.couponAmount : 0) +
						parseFloat(data.memberDiscountBalance ? data.memberDiscountBalance : 0) +
						parseFloat(data.discountBalance ? data.discountBalance : 0) +
						parseFloat(data.groupDiscountBalance ? data.groupDiscountBalance : 0) +
						parseFloat(data.deductibleBalance ? data.deductibleBalance : 0)
					).toFixed(2);

					// // 831已优惠总金额赋值
					// data.allCouponAmount = (
					//     parseFloat(data.totalDiscountBalance ? data.totalDiscountBalance : 0)
					// ).toFixed(2);

					console.log('电站促销字段==>', data.discountBalance)
					console.log('集团折扣字段==>', data.groupDiscountBalance)

					// 总优惠大于总费用显示总费用
					console.log(data.couponAmount, data.memberDiscountBalance, data.discountBalance, data.deductibleBalance)
					console.log(data.allCouponAmount, data.busBalance)
					console.log((+data.allCouponAmount) > (+data.busBalance))
					data.allCouponAmount = ((+data.allCouponAmount) > (+data.busBalance)) ? data.busBalance : data
						.allCouponAmount

					// 计算应付金额  = 总金额 - 总优惠
					data.actualBalance1 = (data.busBalance - data.allCouponAmount).toFixed(2)

					console.log(data.allCouponAmount, data.busBalance)
					// busBalance
					data.paidinAmount = (data.busBalance - data.allCouponAmount).toFixed(2);
					if (data.busBalance - data.allCouponAmount <= 0) {
						data.paidinAmount = '0.00'
					}
					that.setData({
						detailBill: data
					});
					console.log("打印订单详情", data, that.detailBill)

					// data.wxppOrder == true 微信支付分调用倒计时
					if (data.billStatus == 11 || data.wxppOrder) {
						that.sendmessg();
					}



					uni.hideLoading();
				})['catch'](function() {
					uni.hideLoading();
				});
			},

			sendmessg: function() {
				var that = this;
				var time = this.detailBill.leftSecond || 60;
				that.inter = setInterval(function() {
					that.getmsg = time
					time--;
					if (time < 0 && that.detailBill.billStatus == 11) {
						clearInterval(that.inter);
						that.payCharge();
						that.getmsg = 0
					}
				}, 1000);
			},

			//计算时间差
			getDateDiff: function(startTime, endTime) {
				//将日期字符串转换为时间戳
				var sTime = Date.parse(startTime.replace(/-/g, '/')); //开始时间

				var eTime = Date.parse(endTime.replace(/-/g, '/')); //结束时间
				//作为除数的数字

				var divNumSecond = 1000;
				var divNumMinute = 1000 * 60;
				var divNumHour = 1000 * 3600;
				var divNumDay = 1000 * 3600 * 24;
				var day = parseInt((eTime - sTime) / parseInt(divNumDay));
				var hour = parseInt(((eTime - sTime) % parseInt(divNumDay)) / parseInt(divNumHour));
				var minute = parseInt(parseInt(((eTime - sTime) % parseInt(divNumDay)) % parseInt(divNumHour)) / parseInt(
					divNumMinute));
				var second = (parseInt(((eTime - sTime) % parseInt(divNumDay)) % parseInt(divNumHour)) % parseInt(
					divNumMinute)) / parseInt(divNumSecond);
				var time = day * 24 + hour;



				var str = time * 60 + minute + 1;
				return str;
			},

			//获取优惠券列表
			goCoupon: function(e) {
				if (this.detailBill.billStatus == 13) {
					return
				}
				if (this.couponIdStr) {
					if (this.detailBill.billStatus != 14) {
						uni.navigateTo({
							url: '../useCoupon/useCoupon?billId=' + e.currentTarget.dataset.id + '&couponIdStr=' + this
								.couponIdStr
						});
					}
				} else {
					if (this.detailBill.billStatus != 14) {
						uni.navigateTo({
							url: '../useCoupon/useCoupon?billId=' + e.currentTarget.dataset.id
						});
					}
				}
			},

			//免单提示
			showFeeSingle: function() {
				uni.showModal({
					title: '信息提示',
					content: '本单为免服务费单，不可使用优惠券',
					showCancel: false
				});
			},

			//充值弹窗
			rechargeVisible: function(e, _dataset) {
				// var type = e.currentTarget.dataset.type;
				// console.log(e)
				// if(getApp().globalData.sellerNo == 'hyc'){
				uni.navigateTo({
					url: '/mine/pages/recharge/recharge'
				})
				// return 
				// }

				// if (type === 'open') {
				//     this.showRecharge =true
				// }
			},
			rechargeVisible1() {
				this.showRecharge = false
			},


			// 获取个人信息
			getMemberInfo: function() {
				var that = this;
				return https_1.getMemberInfo().then(function(res) {
					var data = res.data;
					if (data.accountBalance) {
						data.accountBalance = (data.accountBalance / 100).toFixed(2);
					} else {
						data.accountBalance = '0.00';
					}

					if (data.carAccountBalance) {
						data.carAccountBalance = (data.carAccountBalance / 100).toFixed(2);
					} else {
						data.carAccountBalance = '0.00';
					}
					that.memberInfo = data,
						that.showRecharge = false
				});
			},

			payCharge: function() {
				console.log('进入')
				//    if(this.alertShow){
				//         this.$refs.alertDialog.open()
				//         return
				//    }
				var that = this;
				uni.showLoading({
					title: '支付中~',
					mask: true
				});
				var id = this.detailBill.id;
				var couponIdStr = this.couponIdStr ? this.couponIdStr : null;


				// 831通知扣费接口调整 根据状态
				let v2True = true;
				let dataQuery = {
					id: id,
					couponIdStr: couponIdStr
				}
				let delayUrl = v2True ? delayDeductionChargeV2({
						...dataQuery
					}) : https_1
					.delayDeductionCharge({
						...dataQuery
					})
				console.log(delayUrl, '调用哪个接口通知支付订单...')

				// https_1
				//     .delayDeductionCharge({
				//         id: id,
				//         couponIdStr: couponIdStr
				//     })

				const chargeTypeStr = this.isv2g ? '放电' : '充电'

				delayUrl
					.then(function(res) {
						console.log(res, 'delayDeductionCharge....')
						if (res.code == 0) {
							uni.hideLoading()
							clearInterval(that.inter);
							// 充电订单已支付成功！请X分钟内驶离充电车位, 否则将会产生占位费用。
							let content = that.detailBill.stationOccupy == 1 ?
								`${chargeTypeStr}订单已支付成功！请${that.detailBill.freeOccupyTime}分钟内驶离${chargeTypeStr}车位，否则将会产生占位费用。` :
								`${chargeTypeStr}订单已支付成功！请及时驶离${chargeTypeStr}车位， 共建文明${chargeTypeStr}环境。`
							// 微信支付分另外判断提示语
							if (that.detailBill.wxppOrder) {
								content = that.detailBill.stationOccupy == 1 ?
									`微信支付分扣款有延迟，请${that.detailBill.freeOccupyTime}分钟内驶离${chargeTypeStr}车位，否则将会产生占位费用。` :
									`微信支付分扣款有延迟，请及时驶离${chargeTypeStr}车位， 共建文明${chargeTypeStr}环境。`
								that.detailBill.isPay = true
							}
							uni.showModal({
								title: '提示',
								content,
								showCancel: false,
								confirmColor: that.objColor2.textColor,
								success: function(res) {
									console.log(res)
									if (res.confirm) {
										// 说明：因后端即充即退订单状态有延迟，所以此处做延时处理， 2s 延迟
										uni.showLoading({
											title: '正在跳转中~',
											mask: true
										});
										setTimeout(() => {
											uni.hideLoading()
											if (!that.marketingSwitch) {
												uni.redirectTo({
													url: '/orderSub/pages/orderDetails/orderDetails?orderId=' + id
												});
											} else {
												uni.redirectTo({
													url: '/orderSub/pages/orderDetailsYxhk/orderDetailsYxhk?orderId=' + id
												});
											}
										}, 2000)

										// uni.redirectTo({
										//     url: '/orderSub/pages/orderDetails/orderDetails?orderId='+id
										// });
									}
								}
							});
						} else if (res.code == -2) {
							uni.hideLoading()
							// clearInterval(that.inter);//打开读秒就不读了
							that.setData({
								alertMsg: "当前订单支付状态异常，请联系平台客服人员进行处理。订单号：" + that.detailBill.busShowNo,
								// alertShow: true,
							})
							that.$refs.alertDialog.open()
						} else {
							clearInterval(that.inter);
							uni.hideLoading()
						}
					});
			}
		}
	};
</script>
<style lang="less">
	@import "@/commin/flex.less";
	@import "./orderSettlement.less";

	.header-image {
		position: absolute;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 556rpx;
	}

	.detCon {
		width: 100%;
		position: relative;
	}

	.titName {
		color: #303133;
		font-size: 30rpx;
		font-weight: bold;
		margin-bottom: 20rpx;
	}

	.titInfoCon {}

	.refundCon {
		width: 100%;
		background: #595c69;
		opacity: 0.6;
		height: 80rpx;
		line-height: 80rpx;
		color: #ffffff;
		position: fixed;
		bottom: 200rpx;
		font-size: 28rpx;
		font-weight: 500;

		image {
			height: 32rpx;
			width: 32rpx;
			vertical-align: middle;
			margin: 0 20rpx;
		}
	}

	@import "../../../commin/commin.less";

	//订单被拦截点击确定支付弹窗样式
	.alert_msg {
		.fontsize(28rpx);
		font-family: PingFang SC;
		font-weight: 400;
		color: @text-color3;
		line-height: 34rpx;
	}

	//联系客服样式
	.infos {
		.fontsize(30rpx);
		.lineheight(70rpx);
		font-family: PingFang SC;
		color: @text-color1;
		display: block;
		font-size: 30rpx;

		.infoTitle {
			display: inline-block;
			width: 5em;
			text-align: right;
		}

		.infoValue {
			color: @blue;
		}
	}

	.zhifufen_icon {
		width: 34rpx;
		height: 34rpx;
		margin-right: 10rpx;
	}
</style>